.TH "TCBDB" 3 "2012-08-18" "Man Page" "Tokyo Cabinet"

.SH NAME
tcbdb \- the B+ tree database API

.SH DESCRIPTION
.PP
B+ tree database is a file containing a B+ tree and is handled with the B+ tree database API.
.PP
To use the B+ tree database API, include `\fBtcutil.h\fR', `\fBtcbdb.h\fR', and related standard header files.  Usually, write the following description near the front of a source file.
.PP
.RS
.br
\fB#include <tcutil.h>\fR
.br
\fB#include <tcbdb.h>\fR
.br
\fB#include <stdlib.h>\fR
.br
\fB#include <time.h>\fR
.br
\fB#include <stdbool.h>\fR
.br
\fB#include <stdint.h>\fR
.RE
.PP
Objects whose type is pointer to `\fBTCBDB\fR' are used to handle B+ tree databases.  A B+ tree database object is created with the function `\fBtcbdbnew\fR' and is deleted with the function `\fBtcbdbdel\fR'.  To avoid memory leak, it is important to delete every object when it is no longer in use.
.PP
Before operations to store or retrieve records, it is necessary to open a database file and connect the B+ tree database object to it.  The function `\fBtcbdbopen\fR' is used to open a database file and the function `\fBtcbdbclose\fR' is used to close the database file.  To avoid data missing or corruption, it is important to close every database file when it is no longer in use.  It is forbidden for multible database objects in a process to open the same database at the same time.

.SH API
.PP
The function `tcbdberrmsg' is used in order to get the message string corresponding to an error code.
.PP
.RS
.br
\fBconst char *tcbdberrmsg(int \fIecode\fB);\fR
.RS
`\fIecode\fR' specifies the error code.
.RE
.RS
The return value is the message string of the error code.
.RE
.RE
.PP
The function `tcbdbnew' is used in order to create a B+ tree database object.
.PP
.RS
.br
\fBTCBDB *tcbdbnew(void);\fR
.RS
The return value is the new B+ tree database object.
.RE
.RE
.PP
The function `tcbdbdel' is used in order to delete a B+ tree database object.
.PP
.RS
.br
\fBvoid tcbdbdel(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
If the database is not closed, it is closed implicitly.  Note that the deleted object and its derivatives can not be used anymore.
.RE
.RE
.PP
The function `tcbdbecode' is used in order to get the last happened error code of a B+ tree database object.
.PP
.RS
.br
\fBint tcbdbecode(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
The return value is the last happened error code.
.RE
.RS
The following error codes are defined: `TCESUCCESS' for success, `TCETHREAD' for threading error, `TCEINVALID' for invalid operation, `TCENOFILE' for file not found, `TCENOPERM' for no permission, `TCEMETA' for invalid meta data, `TCERHEAD' for invalid record header, `TCEOPEN' for open error, `TCECLOSE' for close error, `TCETRUNC' for trunc error, `TCESYNC' for sync error, `TCESTAT' for stat error, `TCESEEK' for seek error, `TCEREAD' for read error, `TCEWRITE' for write error, `TCEMMAP' for mmap error, `TCELOCK' for lock error, `TCEUNLINK' for unlink error, `TCERENAME' for rename error, `TCEMKDIR' for mkdir error, `TCERMDIR' for rmdir error, `TCEKEEP' for existing record, `TCENOREC' for no record found, and `TCEMISC' for miscellaneous error.
.RE
.RE
.PP
The function `tcbdbsetmutex' is used in order to set mutual exclusion control of a B+ tree database object for threading.
.PP
.RS
.br
\fBbool tcbdbsetmutex(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object which is not opened.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
Note that the mutual exclusion control of the database should be set before the database is opened.
.RE
.RE
.PP
The function `tcbdbsetcmpfunc' is used in order to set the custom comparison function of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbsetcmpfunc(TCBDB *\fIbdb\fB, TCCMP \fIcmp\fB, void *\fIcmpop\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object which is not opened.
.RE
.RS
`\fIcmp\fR' specifies the pointer to the custom comparison function.  It receives five parameters.  The first parameter is the pointer to the region of one key.  The second parameter is the size of the region of one key.  The third parameter is the pointer to the region of the other key.  The fourth parameter is the size of the region of the other key.  The fifth parameter is the pointer to the optional opaque object.  It returns positive if the former is big, negative if the latter is big, 0 if both are equivalent.
.RE
.RS
`\fIcmpop\fR' specifies an arbitrary pointer to be given as a parameter of the comparison function.  If it is not needed, `NULL' can be specified.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
The default comparison function compares keys of two records by lexical order.  The functions `tccmplexical' (dafault), `tccmpdecimal', `tccmpint32', and `tccmpint64' are built\-in.  Note that the comparison function should be set before the database is opened.  Moreover, user\-defined comparison functions should be set every time the database is being opened.
.RE
.RE
.PP
The function `tcbdbtune' is used in order to set the tuning parameters of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbtune(TCBDB *\fIbdb\fB, int32_t \fIlmemb\fB, int32_t \fInmemb\fB, int64_t \fIbnum\fB, int8_t \fIapow\fB, int8_t \fIfpow\fB, uint8_t \fIopts\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object which is not opened.
.RE
.RS
`\fIlmemb\fR' specifies the number of members in each leaf page.  If it is not more than 0, the default value is specified.  The default value is 128.
.RE
.RS
`\fInmemb\fR' specifies the number of members in each non\-leaf page.  If it is not more than 0, the default value is specified.  The default value is 256.
.RE
.RS
`\fIbnum\fR' specifies the number of elements of the bucket array.  If it is not more than 0, the default value is specified.  The default value is 16381.  Suggested size of the bucket array is about from 1 to 4 times of the number of all pages to be stored.
.RE
.RS
`\fIapow\fR' specifies the size of record alignment by power of 2.  If it is negative, the default value is specified.  The default value is 8 standing for 2^8=256.
.RE
.RS
`\fIfpow\fR' specifies the maximum number of elements of the free block pool by power of 2.  If it is negative, the default value is specified.  The default value is 10 standing for 2^10=1024.
.RE
.RS
`\fIopts\fR' specifies options by bitwise-or: `BDBTLARGE' specifies that the size of the database can be larger than 2GB by using 64\-bit bucket array, `BDBTDEFLATE' specifies that each page is compressed with Deflate encoding, `BDBTBZIP' specifies that each page is compressed with BZIP2 encoding, `BDBTTCBS' specifies that each page is compressed with TCBS encoding.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
Note that the tuning parameters should be set before the database is opened.
.RE
.RE
.PP
The function `tcbdbsetcache' is used in order to set the caching parameters of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbsetcache(TCBDB *\fIbdb\fB, int32_t \fIlcnum\fB, int32_t \fIncnum\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object which is not opened.
.RE
.RS
`\fIlcnum\fR' specifies the maximum number of leaf nodes to be cached.  If it is not more than 0, the default value is specified.  The default value is 1024.
.RE
.RS
`\fIncnum\fR' specifies the maximum number of non\-leaf nodes to be cached.  If it is not more than 0, the default value is specified.  The default value is 512.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
Note that the caching parameters should be set before the database is opened.
.RE
.RE
.PP
The function `tcbdbsetxmsiz' is used in order to set the size of the extra mapped memory of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbsetxmsiz(TCBDB *\fIbdb\fB, int64_t \fIxmsiz\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object which is not opened.
.RE
.RS
`\fIxmsiz\fR' specifies the size of the extra mapped memory.  If it is not more than 0, the extra mapped memory is disabled.  It is disabled by default.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
Note that the mapping parameters should be set before the database is opened.
.RE
.RE
.PP
The function `tcbdbsetdfunit' is used in order to set the unit step number of auto defragmentation of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbsetdfunit(TCBDB *\fIbdb\fB, int32_t \fIdfunit\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object which is not opened.
.RE
.RS
`\fIdfunit\fR' specifie the unit step number.  If it is not more than 0, the auto defragmentation is disabled.  It is disabled by default.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
Note that the defragmentation parameter should be set before the database is opened.
.RE
.RE
.PP
The function `tcbdbopen' is used in order to open a database file and connect a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbopen(TCBDB *\fIbdb\fB, const char *\fIpath\fB, int \fIomode\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object which is not opened.
.RE
.RS
`\fIpath\fR' specifies the path of the database file.
.RE
.RS
`\fIomode\fR' specifies the connection mode: `BDBOWRITER' as a writer, `BDBOREADER' as a reader.  If the mode is `BDBOWRITER', the following may be added by bitwise-or: `BDBOCREAT', which means it creates a new database if not exist, `BDBOTRUNC', which means it creates a new database regardless if one exists, `BDBOTSYNC', which means every transaction synchronizes updated contents with the device.  Both of `BDBOREADER' and `BDBOWRITER' can be added to by bitwise-or: `BDBONOLCK', which means it opens the database file without file locking, or `BDBOLCKNB', which means locking is performed without blocking.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RE
.PP
The function `tcbdbclose' is used in order to close a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbclose(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
Update of a database is assured to be written when the database is closed.  If a writer opens a database but does not close it appropriately, the database will be broken.
.RE
.RE
.PP
The function `tcbdbput' is used in order to store a record into a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbput(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
`\fIvbuf\fR' specifies the pointer to the region of the value.
.RE
.RS
`\fIvsiz\fR' specifies the size of the region of the value.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
If a record with the same key exists in the database, it is overwritten.
.RE
.RE
.PP
The function `tcbdbput2' is used in order to store a string record into a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbput2(TCBDB *\fIbdb\fB, const char *\fIkstr\fB, const char *\fIvstr\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkstr\fR' specifies the string of the key.
.RE
.RS
`\fIvstr\fR' specifies the string of the value.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
If a record with the same key exists in the database, it is overwritten.
.RE
.RE
.PP
The function `tcbdbputkeep' is used in order to store a new record into a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbputkeep(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
`\fIvbuf\fR' specifies the pointer to the region of the value.
.RE
.RS
`\fIvsiz\fR' specifies the size of the region of the value.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
If a record with the same key exists in the database, this function has no effect.
.RE
.RE
.PP
The function `tcbdbputkeep2' is used in order to store a new string record into a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbputkeep2(TCBDB *\fIbdb\fB, const char *\fIkstr\fB, const char *\fIvstr\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkstr\fR' specifies the string of the key.
.RE
.RS
`\fIvstr\fR' specifies the string of the value.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
If a record with the same key exists in the database, this function has no effect.
.RE
.RE
.PP
The function `tcbdbputcat' is used in order to concatenate a value at the end of the existing record in a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbputcat(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
`\fIvbuf\fR' specifies the pointer to the region of the value.
.RE
.RS
`\fIvsiz\fR' specifies the size of the region of the value.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
If there is no corresponding record, a new record is created.
.RE
.RE
.PP
The function `tcbdbputcat2' is used in order to concatenate a string value at the end of the existing record in a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbputcat2(TCBDB *\fIbdb\fB, const char *\fIkstr\fB, const char *\fIvstr\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkstr\fR' specifies the string of the key.
.RE
.RS
`\fIvstr\fR' specifies the string of the value.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
If there is no corresponding record, a new record is created.
.RE
.RE
.PP
The function `tcbdbputdup' is used in order to store a record into a B+ tree database object with allowing duplication of keys.
.PP
.RS
.br
\fBbool tcbdbputdup(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, const void *\fIvbuf\fB, int \fIvsiz\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
`\fIvbuf\fR' specifies the pointer to the region of the value.
.RE
.RS
`\fIvsiz\fR' specifies the size of the region of the value.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
If a record with the same key exists in the database, the new record is placed after the existing one.
.RE
.RE
.PP
The function `tcbdbputdup2' is used in order to store a string record into a B+ tree database object with allowing duplication of keys.
.PP
.RS
.br
\fBbool tcbdbputdup2(TCBDB *\fIbdb\fB, const char *\fIkstr\fB, const char *\fIvstr\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkstr\fR' specifies the string of the key.
.RE
.RS
`\fIvstr\fR' specifies the string of the value.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
If a record with the same key exists in the database, the new record is placed after the existing one.
.RE
.RE
.PP
The function `tcbdbputdup3' is used in order to store records into a B+ tree database object with allowing duplication of keys.
.PP
.RS
.br
\fBbool tcbdbputdup3(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, const TCLIST *\fIvals\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the common key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the common key.
.RE
.RS
`\fIvals\fR' specifies a list object containing values.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
If a record with the same key exists in the database, the new records are placed after the existing one.
.RE
.RE
.PP
The function `tcbdbout' is used in order to remove a record of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbout(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
If the key of duplicated records is specified, the first one is selected.
.RE
.RE
.PP
The function `tcbdbout2' is used in order to remove a string record of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbout2(TCBDB *\fIbdb\fB, const char *\fIkstr\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkstr\fR' specifies the string of the key.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
If the key of duplicated records is specified, the first one is selected.
.RE
.RE
.PP
The function `tcbdbout3' is used in order to remove records of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbout3(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
If the key of duplicated records is specified, all of them are removed.
.RE
.RE
.PP
The function `tcbdbget' is used in order to retrieve a record in a B+ tree database object.
.PP
.RS
.br
\fBvoid *tcbdbget(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, int *\fIsp\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
`\fIsp\fR' specifies the pointer to the variable into which the size of the region of the return value is assigned.
.RE
.RS
If successful, the return value is the pointer to the region of the value of the corresponding record.  `NULL' is returned if no record corresponds.
.RE
.RS
If the key of duplicated records is specified, the first one is selected.  Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.  Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.
.RE
.RE
.PP
The function `tcbdbget2' is used in order to retrieve a string record in a B+ tree database object.
.PP
.RS
.br
\fBchar *tcbdbget2(TCBDB *\fIbdb\fB, const char *\fIkstr\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIkstr\fR' specifies the string of the key.
.RE
.RS
If successful, the return value is the string of the value of the corresponding record.  `NULL' is returned if no record corresponds.
.RE
.RS
If the key of duplicated records is specified, the first one is selected.  Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.
.RE
.RE
.PP
The function `tcbdbget3' is used in order to retrieve a record in a B+ tree database object as a volatile buffer.
.PP
.RS
.br
\fBconst void *tcbdbget3(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, int *\fIsp\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
`\fIsp\fR' specifies the pointer to the variable into which the size of the region of the return value is assigned.
.RE
.RS
If successful, the return value is the pointer to the region of the value of the corresponding record.  `NULL' is returned if no record corresponds.
.RE
.RS
If the key of duplicated records is specified, the first one is selected.  Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.  Because the region of the return value is volatile and it may be spoiled by another operation of the database, the data should be copied into another involatile buffer immediately.
.RE
.RE
.PP
The function `tcbdbget4' is used in order to retrieve records in a B+ tree database object.
.PP
.RS
.br
\fBTCLIST *tcbdbget4(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
If successful, the return value is a list object of the values of the corresponding records.  `NULL' is returned if no record corresponds.
.RE
.RS
Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use.
.RE
.RE
.PP
The function `tcbdbvnum' is used in order to get the number of records corresponding a key in a B+ tree database object.
.PP
.RS
.br
\fBint tcbdbvnum(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
If successful, the return value is the number of the corresponding records, else, it is 0.
.RE
.RE
.PP
The function `tcbdbvnum2' is used in order to get the number of records corresponding a string key in a B+ tree database object.
.PP
.RS
.br
\fBint tcbdbvnum2(TCBDB *\fIbdb\fB, const char *\fIkstr\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIkstr\fR' specifies the string of the key.
.RE
.RS
If successful, the return value is the number of the corresponding records, else, it is 0.
.RE
.RE
.PP
The function `tcbdbvsiz' is used in order to get the size of the value of a record in a B+ tree database object.
.PP
.RS
.br
\fBint tcbdbvsiz(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
If successful, the return value is the size of the value of the corresponding record, else, it is \-1.
.RE
.RS
If the key of duplicated records is specified, the first one is selected.
.RE
.RE
.PP
The function `tcbdbvsiz2' is used in order to get the size of the value of a string record in a B+ tree database object.
.PP
.RS
.br
\fBint tcbdbvsiz2(TCBDB *\fIbdb\fB, const char *\fIkstr\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIkstr\fR' specifies the string of the key.
.RE
.RS
If successful, the return value is the size of the value of the corresponding record, else, it is \-1.
.RE
.RS
If the key of duplicated records is specified, the first one is selected.
.RE
.RE
.PP
The function `tcbdbrange' is used in order to get keys of ranged records in a B+ tree database object.
.PP
.RS
.br
\fBTCLIST *tcbdbrange(TCBDB *\fIbdb\fB, const void *\fIbkbuf\fB, int \fIbksiz\fB, bool \fIbinc\fB, const void *\fIekbuf\fB, int \fIeksiz\fB, bool \fIeinc\fB, int \fImax\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIbkbuf\fR' specifies the pointer to the region of the key of the beginning border.  If it is `NULL', the first record is specified.
.RE
.RS
`\fIbksiz\fR' specifies the size of the region of the beginning key.
.RE
.RS
`\fIbinc\fR' specifies whether the beginning border is inclusive or not.
.RE
.RS
`\fIekbuf\fR' specifies the pointer to the region of the key of the ending border.  If it is `NULL', the last record is specified.
.RE
.RS
`\fIeksiz\fR' specifies the size of the region of the ending key.
.RE
.RS
`\fIeinc\fR' specifies whether the ending border is inclusive or not.
.RE
.RS
`\fImax\fR' specifies the maximum number of keys to be fetched.  If it is negative, no limit is specified.
.RE
.RS
The return value is a list object of the keys of the corresponding records.  This function does never fail.  It returns an empty list even if no record corresponds.
.RE
.RS
Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use.
.RE
.RE
.PP
The function `tcbdbrange2' is used in order to get string keys of ranged records in a B+ tree database object.
.PP
.RS
.br
\fBTCLIST *tcbdbrange2(TCBDB *\fIbdb\fB, const char *\fIbkstr\fB, bool \fIbinc\fB, const char *\fIekstr\fB, bool \fIeinc\fB, int \fImax\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIbkstr\fR' specifies the string of the key of the beginning border.  If it is `NULL', the first record is specified.
.RE
.RS
`\fIbinc\fR' specifies whether the beginning border is inclusive or not.
.RE
.RS
`\fIekstr\fR' specifies the string of the key of the ending border.  If it is `NULL', the last record is specified.
.RE
.RS
`\fIeinc\fR' specifies whether the ending border is inclusive or not.
.RE
.RS
`\fImax\fR' specifies the maximum number of keys to be fetched.  If it is negative, no limit is specified.
.RE
.RS
The return value is a list object of the keys of the corresponding records.  This function does never fail.  It returns an empty list even if no record corresponds.
.RE
.RS
Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use.
.RE
.RE
.PP
The function `tcbdbfwmkeys' is used in order to get forward matching keys in a B+ tree database object.
.PP
.RS
.br
\fBTCLIST *tcbdbfwmkeys(TCBDB *\fIbdb\fB, const void *\fIpbuf\fB, int \fIpsiz\fB, int \fImax\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIpbuf\fR' specifies the pointer to the region of the prefix.
.RE
.RS
`\fIpsiz\fR' specifies the size of the region of the prefix.
.RE
.RS
`\fImax\fR' specifies the maximum number of keys to be fetched.  If it is negative, no limit is specified.
.RE
.RS
The return value is a list object of the corresponding keys.  This function does never fail.  It returns an empty list even if no key corresponds.
.RE
.RS
Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use.
.RE
.RE
.PP
The function `tcbdbfwmkeys2' is used in order to get forward matching string keys in a B+ tree database object.
.PP
.RS
.br
\fBTCLIST *tcbdbfwmkeys2(TCBDB *\fIbdb\fB, const char *\fIpstr\fB, int \fImax\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIpstr\fR' specifies the string of the prefix.
.RE
.RS
`\fImax\fR' specifies the maximum number of keys to be fetched.  If it is negative, no limit is specified.
.RE
.RS
The return value is a list object of the corresponding keys.  This function does never fail.  It returns an empty list even if no key corresponds.
.RE
.RS
Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use.
.RE
.RE
.PP
The function `tcbdbaddint' is used in order to add an integer to a record in a B+ tree database object.
.PP
.RS
.br
\fBint tcbdbaddint(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, int \fInum\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
`\fInum\fR' specifies the additional value.
.RE
.RS
If successful, the return value is the summation value, else, it is `INT_MIN'.
.RE
.RS
If the corresponding record exists, the value is treated as an integer and is added to.  If no record corresponds, a new record of the additional value is stored.
.RE
.RE
.PP
The function `tcbdbadddouble' is used in order to add a real number to a record in a B+ tree database object.
.PP
.RS
.br
\fBdouble tcbdbadddouble(TCBDB *\fIbdb\fB, const void *\fIkbuf\fB, int \fIksiz\fB, double \fInum\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
`\fInum\fR' specifies the additional value.
.RE
.RS
If successful, the return value is the summation value, else, it is Not-a-Number.
.RE
.RS
If the corresponding record exists, the value is treated as a real number and is added to.  If no record corresponds, a new record of the additional value is stored.
.RE
.RE
.PP
The function `tcbdbsync' is used in order to synchronize updated contents of a B+ tree database object with the file and the device.
.PP
.RS
.br
\fBbool tcbdbsync(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
This function is useful when another process connects to the same database file.
.RE
.RE
.PP
The function `tcbdboptimize' is used in order to optimize the file of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdboptimize(TCBDB *\fIbdb\fB, int32_t \fIlmemb\fB, int32_t \fInmemb\fB, int64_t \fIbnum\fB, int8_t \fIapow\fB, int8_t \fIfpow\fB, uint8_t \fIopts\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
`\fIlmemb\fR' specifies the number of members in each leaf page.  If it is not more than 0, the current setting is not changed.
.RE
.RS
`\fInmemb\fR' specifies the number of members in each non\-leaf page.  If it is not more than 0, the current setting is not changed.
.RE
.RS
`\fIbnum\fR' specifies the number of elements of the bucket array.  If it is not more than 0, the default value is specified.  The default value is two times of the number of pages.
.RE
.RS
`\fIapow\fR' specifies the size of record alignment by power of 2.  If it is negative, the current setting is not changed.
.RE
.RS
`\fIfpow\fR' specifies the maximum number of elements of the free block pool by power of 2.  If it is negative, the current setting is not changed.
.RE
.RS
`\fIopts\fR' specifies options by bitwise-or: `BDBTLARGE' specifies that the size of the database can be larger than 2GB by using 64\-bit bucket array, `BDBTDEFLATE' specifies that each record is compressed with Deflate encoding, `BDBTBZIP' specifies that each page is compressed with BZIP2 encoding, `BDBTTCBS' specifies that each page is compressed with TCBS encoding.  If it is `UINT8_MAX', the current setting is not changed.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
This function is useful to reduce the size of the database file with data fragmentation by successive updating.
.RE
.RE
.PP
The function `tcbdbvanish' is used in order to remove all records of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbvanish(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RE
.PP
The function `tcbdbcopy' is used in order to copy the database file of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbcopy(TCBDB *\fIbdb\fB, const char *\fIpath\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
`\fIpath\fR' specifies the path of the destination file.  If it begins with `@', the trailing substring is executed as a command line.
.RE
.RS
If successful, the return value is true, else, it is false.  False is returned if the executed command returns non\-zero code.
.RE
.RS
The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress.  So, this function is useful to create a backup file of the database file.
.RE
.RE
.PP
The function `tcbdbtranbegin' is used in order to begin the transaction of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbtranbegin(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time.  Thus, the serializable isolation level is assumed if every database operation is performed in the transaction.  Because all pages are cached on memory while the transaction, the amount of referred records is limited by the memory capacity.  If the database is closed during transaction, the transaction is aborted implicitly.
.RE
.RE
.PP
The function `tcbdbtrancommit' is used in order to commit the transaction of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbtrancommit(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
Update in the transaction is fixed when it is committed successfully.
.RE
.RE
.PP
The function `tcbdbtranabort' is used in order to abort the transaction of a B+ tree database object.
.PP
.RS
.br
\fBbool tcbdbtranabort(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object connected as a writer.
.RE
.RS
If successful, the return value is true, else, it is false.
.RE
.RS
Update in the transaction is discarded when it is aborted.  The state of the database is rollbacked to before transaction.
.RE
.RE
.PP
The function `tcbdbpath' is used in order to get the file path of a B+ tree database object.
.PP
.RS
.br
\fBconst char *tcbdbpath(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
The return value is the path of the database file or `NULL' if the object does not connect to any database file.
.RE
.RE
.PP
The function `tcbdbrnum' is used in order to get the number of records of a B+ tree database object.
.PP
.RS
.br
\fBuint64_t tcbdbrnum(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
The return value is the number of records or 0 if the object does not connect to any database file.
.RE
.RE
.PP
The function `tcbdbfsiz' is used in order to get the size of the database file of a B+ tree database object.
.PP
.RS
.br
\fBuint64_t tcbdbfsiz(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
The return value is the size of the database file or 0 if the object does not connect to any database file.
.RE
.RE
.PP
The function `tcbdbcurnew' is used in order to create a cursor object.
.PP
.RS
.br
\fBBDBCUR *tcbdbcurnew(TCBDB *\fIbdb\fB);\fR
.RS
`\fIbdb\fR' specifies the B+ tree database object.
.RE
.RS
The return value is the new cursor object.
.RE
.RS
Note that the cursor is available only after initialization with the `tcbdbcurfirst' or the `tcbdbcurjump' functions and so on.  Moreover, the position of the cursor will be indefinite when the database is updated after the initialization of the cursor.
.RE
.RE
.PP
The function `tcbdbcurdel' is used in order to delete a cursor object.
.PP
.RS
.br
\fBvoid tcbdbcurdel(BDBCUR *\fIcur\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RE
.PP
The function `tcbdbcurfirst' is used in order to move a cursor object to the first record.
.PP
.RS
.br
\fBbool tcbdbcurfirst(BDBCUR *\fIcur\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
If successful, the return value is true, else, it is false.  False is returned if there is no record in the database.
.RE
.RE
.PP
The function `tcbdbcurlast' is used in order to move a cursor object to the last record.
.PP
.RS
.br
\fBbool tcbdbcurlast(BDBCUR *\fIcur\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
If successful, the return value is true, else, it is false.  False is returned if there is no record in the database.
.RE
.RE
.PP
The function `tcbdbcurjump' is used in order to move a cursor object to the front of records corresponding a key.
.PP
.RS
.br
\fBbool tcbdbcurjump(BDBCUR *\fIcur\fB, const void *\fIkbuf\fB, int \fIksiz\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
`\fIkbuf\fR' specifies the pointer to the region of the key.
.RE
.RS
`\fIksiz\fR' specifies the size of the region of the key.
.RE
.RS
If successful, the return value is true, else, it is false.  False is returned if there is no record corresponding the condition.
.RE
.RS
The cursor is set to the first record corresponding the key or the next substitute if completely matching record does not exist.
.RE
.RE
.PP
The function `tcbdbcurjump2' is used in order to move a cursor object to the front of records corresponding a key string.
.PP
.RS
.br
\fBbool tcbdbcurjump2(BDBCUR *\fIcur\fB, const char *\fIkstr\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
`\fIkstr\fR' specifies the string of the key.
.RE
.RS
If successful, the return value is true, else, it is false.  False is returned if there is no record corresponding the condition.
.RE
.RS
The cursor is set to the first record corresponding the key or the next substitute if completely matching record does not exist.
.RE
.RE
.PP
The function `tcbdbcurprev' is used in order to move a cursor object to the previous record.
.PP
.RS
.br
\fBbool tcbdbcurprev(BDBCUR *\fIcur\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
If successful, the return value is true, else, it is false.  False is returned if there is no previous record.
.RE
.RE
.PP
The function `tcbdbcurnext' is used in order to move a cursor object to the next record.
.PP
.RS
.br
\fBbool tcbdbcurnext(BDBCUR *\fIcur\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
If successful, the return value is true, else, it is false.  False is returned if there is no next record.
.RE
.RE
.PP
The function `tcbdbcurput' is used in order to insert a record around a cursor object.
.PP
.RS
.br
\fBbool tcbdbcurput(BDBCUR *\fIcur\fB, const void *\fIvbuf\fB, int \fIvsiz\fB, int \fIcpmode\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object of writer connection.
.RE
.RS
`\fIvbuf\fR' specifies the pointer to the region of the value.
.RE
.RS
`\fIvsiz\fR' specifies the size of the region of the value.
.RE
.RS
`\fIcpmode\fR' specifies detail adjustment: `BDBCPCURRENT', which means that the value of the current record is overwritten, `BDBCPBEFORE', which means that the new record is inserted before the current record, `BDBCPAFTER', which means that the new record is inserted after the current record.
.RE
.RS
If successful, the return value is true, else, it is false.  False is returned when the cursor is at invalid position.
.RE
.RS
After insertion, the cursor is moved to the inserted record.
.RE
.RE
.PP
The function `tcbdbcurput2' is used in order to insert a string record around a cursor object.
.PP
.RS
.br
\fBbool tcbdbcurput2(BDBCUR *\fIcur\fB, const char *\fIvstr\fB, int \fIcpmode\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object of writer connection.
.RE
.RS
`\fIvstr\fR' specifies the string of the value.
.RE
.RS
`\fIcpmode\fR' specifies detail adjustment: `BDBCPCURRENT', which means that the value of the current record is overwritten, `BDBCPBEFORE', which means that the new record is inserted before the current record, `BDBCPAFTER', which means that the new record is inserted after the current record.
.RE
.RS
If successful, the return value is true, else, it is false.  False is returned when the cursor is at invalid position.
.RE
.RS
After insertion, the cursor is moved to the inserted record.
.RE
.RE
.PP
The function `tcbdbcurout' is used in order to remove the record where a cursor object is.
.PP
.RS
.br
\fBbool tcbdbcurout(BDBCUR *\fIcur\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object of writer connection.
.RE
.RS
If successful, the return value is true, else, it is false.  False is returned when the cursor is at invalid position.
.RE
.RS
After deletion, the cursor is moved to the next record if possible.
.RE
.RE
.PP
The function `tcbdbcurkey' is used in order to get the key of the record where the cursor object is.
.PP
.RS
.br
\fBchar *tcbdbcurkey(BDBCUR *\fIcur\fB, int *\fIsp\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
`\fIsp\fR' specifies the pointer to the variable into which the size of the region of the return value is assigned.
.RE
.RS
If successful, the return value is the pointer to the region of the key, else, it is `NULL'.  `NULL' is returned when the cursor is at invalid position.
.RE
.RS
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.  Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.
.RE
.RE
.PP
The function `tcbdbcurkey2' is used in order to get the key string of the record where the cursor object is.
.PP
.RS
.br
\fBchar *tcbdbcurkey2(BDBCUR *\fIcur\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
If successful, the return value is the string of the key, else, it is `NULL'.  `NULL' is returned when the cursor is at invalid position.
.RE
.RS
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.
.RE
.RE
.PP
The function `tcbdbcurkey3' is used in order to get the key of the record where the cursor object is, as a volatile buffer.
.PP
.RS
.br
\fBconst char *tcbdbcurkey3(BDBCUR *\fIcur\fB, int *\fIsp\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
`\fIsp\fR' specifies the pointer to the variable into which the size of the region of the return value is assigned.
.RE
.RS
If successful, the return value is the pointer to the region of the key, else, it is `NULL'.  `NULL' is returned when the cursor is at invalid position.
.RE
.RS
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.  Because the region of the return value is volatile and it may be spoiled by another operation of the database, the data should be copied into another involatile buffer immediately.
.RE
.RE
.PP
The function `tcbdbcurval' is used in order to get the value of the record where the cursor object is.
.PP
.RS
.br
\fBchar *tcbdbcurval(BDBCUR *\fIcur\fB, int *\fIsp\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
`\fIsp\fR' specifies the pointer to the variable into which the size of the region of the return value is assigned.
.RE
.RS
If successful, the return value is the pointer to the region of the value, else, it is `NULL'.  `NULL' is returned when the cursor is at invalid position.
.RE
.RS
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.  Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.
.RE
.RE
.PP
The function `tcbdbcurval2' is used in order to get the value string of the record where the cursor object is.
.PP
.RS
.br
\fBchar *tcbdbcurval2(BDBCUR *\fIcur\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
If successful, the return value is the string of the value, else, it is `NULL'.  `NULL' is returned when the cursor is at invalid position.
.RE
.RS
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.
.RE
.RE
.PP
The function `tcbdbcurval3' is used in order to get the value of the record where the cursor object is, as a volatile buffer.
.PP
.RS
.br
\fBconst char *tcbdbcurval3(BDBCUR *\fIcur\fB, int *\fIsp\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
`\fIsp\fR' specifies the pointer to the variable into which the size of the region of the return value is assigned.
.RE
.RS
If successful, the return value is the pointer to the region of the value, else, it is `NULL'.  `NULL' is returned when the cursor is at invalid position.
.RE
.RS
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.  Because the region of the return value is volatile and it may be spoiled by another operation of the database, the data should be copied into another involatile buffer immediately.
.RE
.RE
.PP
The function `tcbdbcurrec' is used in order to get the key and the value of the record where the cursor object is.
.PP
.RS
.br
\fBbool tcbdbcurrec(BDBCUR *\fIcur\fB, TCXSTR *\fIkxstr\fB, TCXSTR *\fIvxstr\fB);\fR
.RS
`\fIcur\fR' specifies the cursor object.
.RE
.RS
`\fIkxstr\fR' specifies the object into which the key is wrote down.
.RE
.RS
`\fIvxstr\fR' specifies the object into which the value is wrote down.
.RE
.RS
If successful, the return value is true, else, it is false.  False is returned when the cursor is at invalid position.
.RE
.RE

.SH SEE ALSO
.PP
.BR tcbtest (1),
.BR tcbmttest (1),
.BR tcbmgr (1),
.BR tokyocabinet (3)
